home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / midaswww-1.0 / SGMLMarkerText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  6.3 KB  |  163 lines

  1. /*==================================================================*/
  2. /*                                                                  */
  3. /* SGMLMarkerTextObject                                             */
  4. /*                                                                  */
  5. /* T.Johnson - (TonyJ@Slacvx.Slac.Stanford.Edu)           June.92   */
  6. /*                                                                  */
  7. /* Defines a marker text segment for the SGMLHyper widget           */
  8. /*                                                                  */
  9. /*==================================================================*/
  10.  
  11. #include <X11/IntrinsicP.h>
  12. #include <X11/StringDefs.h>
  13. #include <X11/CoreP.h>
  14. #include "SGMLMarkerTextP.h"
  15.  
  16. /* 
  17.   Private functions 
  18. */
  19.  
  20.  
  21. /*
  22.   Widget class methods
  23. */
  24.  
  25. static void ComputeSize();
  26.  
  27. #define Offset(field) XtOffsetOf(SGMLMarkerTextRec,sgml_marker_text.field)
  28.  
  29. static XtResource resources[] = {
  30.  
  31.     {SGMLNcolumnAlign,SGMLCColumnAlign,XtRDimension,sizeof(Dimension),
  32.     Offset (column_align),XtRImmediate,(XtPointer)0},
  33.  
  34.     {SGMLNposition,SGMLCPosition,XtRPosition,sizeof(Position),
  35.     Offset (position),XtRImmediate,(XtPointer)-1},
  36.  
  37. };
  38. #undef Offset
  39.  
  40. /*---------------------------------------------------------------*/
  41. /* Static initialisation of the class record                     */
  42. /*---------------------------------------------------------------*/
  43.  
  44. SGMLMarkerTextClassRec  sGMLMarkerTextClassRec = {
  45.     {
  46.     (WidgetClass) &sGMLTextClassRec,     /* superclass            */
  47.     "SGMLMarkerText",                    /* class_name            */
  48.     sizeof(SGMLMarkerTextRec),           /* widget_size           */
  49.     NULL,                                /* class_initialize      */
  50.     NULL,                                /* class_part_initialize */
  51.     FALSE,                               /* class_inited          */
  52.     NULL,                                /* initialize            */
  53.     NULL,                                /* initialize_hook       */
  54.     NULL,                                /* obj1                  */
  55.     NULL,                                /* obj2                  */
  56.     0,                                   /* obj3                  */
  57.     resources,                           /* resources             */
  58.     XtNumber(resources),                 /* num_resources         */
  59.     NULLQUARK,                           /* xrm_class             */
  60.     0,                                   /* obj4                  */
  61.     0,                                   /* obj5                  */
  62.     0,                                   /* obj6                  */
  63.     0,                                   /* obj7                  */
  64.     NULL,                             /* destroy               */
  65.     NULL,                                /* obj8                  */
  66.     NULL,                                /* obj9                  */
  67.     NULL,                                /* set_values            */
  68.     NULL,                                /* set_values_hook       */
  69.     NULL,                                /* obj10                 */
  70.     NULL,                                /* get_values_hook       */
  71.     NULL,                                /* obj11                 */
  72.     XtVersion,                           /* version               */
  73.     NULL,                                /* callback private      */
  74.     NULL,                                /* obj12                 */
  75.     NULL,                                /* obj13                 */
  76.     NULL,                                /* obj14                 */
  77.     NULL,                                /* extension             */
  78.     },
  79.     {
  80.     ComputeSize,                 /* compute_size          */
  81.     SGMLInheritAdjustSize,               /* adjust_size           */
  82.     SGMLInheritAdjustPosition,        /* adjust_position       */
  83.     SGMLInheritExpose,                   /* expose                */
  84.     SGMLInheritActivate,                 /* activate              */
  85.     SGMLInheritHilite,                   /* hilite                */
  86.     SGMLInheritContains,                 /* contains              */
  87.     SGMLInheritCallCreateCallback,       /* call_create_callback  */
  88.     SGMLInheritCallMapCallback,          /* call_map_callback     */
  89.     SGMLInheritMakeVisible,              /* make_visible          */
  90.     NULL,                                /* extension             */
  91.     },
  92.     {
  93.     NULL,                                /* ignore                */
  94.     }
  95. };
  96.  
  97.  
  98. WidgetClass sGMLMarkerTextObjectClass = (WidgetClass) &sGMLMarkerTextClassRec;
  99.  
  100. /*--------------------------------------------------------------*/
  101. /* Compute Size:                                                */
  102. /*--------------------------------------------------------------*/
  103. static void ComputeSize(w,geom)
  104. SGMLMarkerTextObject w;
  105. SGMLGeometry *geom;
  106. {
  107.   Dimension left_clearance  = w->sgml_text.left_margin  + w->sgml_text.left_indent;
  108.   Dimension right_clearance = w->sgml_text.right_margin + w->sgml_text.right_indent;
  109.  
  110.    /*
  111.     * Break?
  112.     */  
  113.  
  114.   if (w->sgml_text.break_before || w->sgml_text.break_after)
  115.   {
  116.     _SGMLBreak(geom,w->sgml_text.space_before);
  117.     _SGMLBreak(geom,w->sgml_text.space_after);
  118.   } 
  119.   else if (w->sgml_marker_text.column_align)
  120.   {
  121.     Dimension x = geom->coord.x;
  122.     
  123.     if (x < left_clearance) x = 0;
  124.     else x -= left_clearance;
  125.  
  126.     if (x%w->sgml_marker_text.column_align)
  127.       x += w->sgml_marker_text.column_align - x%w->sgml_marker_text.column_align;
  128.   
  129.     x += left_clearance;
  130.     geom->coord.x = x; 
  131.     geom->leave_space = FALSE;
  132.  
  133.     if (x + w->sgml_marker_text.column_align + right_clearance > 
  134.         geom->natural_width)
  135.     {
  136.       _SGMLBreak(geom,0);
  137.     }             
  138.   }
  139.   if (w->sgml_marker_text.position >= 0)
  140.   {
  141.     if (geom->coord.x > w->sgml_text.left_margin+w->sgml_marker_text.position)
  142.       {
  143.         _SGMLBreak(geom,0);
  144.       }
  145.     geom->coord.x = w->sgml_text.left_margin+w->sgml_marker_text.position;
  146.     geom->leave_space = FALSE;
  147.     geom->broken = FALSE;
  148.   }
  149. }
  150.  
  151. /*-----------------------------------------------------------------------*/
  152. /* Create a new SGMLMarkerTextObject                                      */
  153. /*-----------------------------------------------------------------------*/
  154.  
  155. Widget SGMLCreateMarkerText(parent,name,al,ac)
  156. Widget parent;
  157. char   *name;
  158. ArgList al;
  159. int     ac;
  160. {
  161.     return XtCreateWidget(name,sGMLMarkerTextObjectClass,parent,al,ac);
  162. }
  163.